package fr.insalyon.sims.broadcast.tests.service;

import java.net.UnknownHostException;
import java.util.HashMap;

import fr.insalyon.sims.broadcast.service.BroadcastReceiverService;
import fr.insalyon.sims.streamManagerClient.Response;

public class BroadcastReceiverServiceTest {
	// ------------------------------------------------------- CONSTANTS -- //
	// ------------------------------------------------------ ATTRIBUTES -- //
	// ---------------------------------------------------- CONSTRUCTORS -- //
	// --------------------------------------------------------- METHODS -- //
	
	public static void main(String[] args) throws UnknownHostException {
		// Default parameters values
		int srcPort = 22592;
		int multicastPort = 4242;
		String multicastIp = "224.0.0.2";
		
		// Command line parameters values
		for (int i = 0; i < args.length; i++) {
			String arg = args[i];
			
			try {
				if (arg.equals("-p") || args.equals("-port"))
					srcPort = Integer.parseInt(args[i + 1]);
				else if (arg.equals("-mip"))
					multicastIp = args[i + 1];
				else if (arg.equals("-mp") || arg.equals("-mport"))
					multicastPort = Integer.parseInt(args[i + 1]);
			} catch (Exception e) {
				System.out.println("Syntax: java -jar broadcast.jar -p <src_port> -mip <multicast_ip> -mp <multicast_port>");
				System.exit(0);
			}
		}
		
		// Receiver service parameters
		HashMap<String, String> receiverParams = new HashMap<String, String>();
		receiverParams.put("destIp", "127.0.0.1");
		receiverParams.put("destPort", String.valueOf(srcPort));
		receiverParams.put("multicastIp", multicastIp);
		receiverParams.put("multicastPort", String.valueOf(multicastPort));

		// Create and start the receiver service
		BroadcastReceiverService receiverService = new BroadcastReceiverService();
		Response receiverResponse = receiverService.doStart(receiverParams);
		System.out.println("[receiver-service] started (response: " + receiverResponse + ")");
	}
	
	// ------------------------------------------------- PRIVATE METHODS -- //
	// --------------------------------------------------- INNER CLASSES -- //
}
